import { useState } from 'react'

function UseState() {
	// 修改基本类型的state
	const [count, setCount] = useState(0)
	const add = () => {
		setCount(count + 1)
	}

	// 修改对象类型的state
	const [person, setPerson] = useState({ name: '张三', age: 20 })
	const changeName = () => {
		setPerson({ ...person, name: '李四' })
	}

	return (
		<>
			<button onClick={add}>点击+1：{count}</button>
			<hr />

			<button onClick={() => changeName('李四')}>点击修改：{person.name}</button>
		</>
	)
}

export default UseState
